const app = getApp();
const ipconfig = app.globalData.ipconfig;

Page({
    data: {
		moment:{
            content:'',
            picture:[],
        },
        pickerHidden: true,
        chosen: '',
        type:''
    },

    onLoad(options) {
        this.setData({
            type:options.type
        })
    },

    uploadpic(){
        const that = this;
        wx.chooseMedia({
            count: 1,
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            mediaType: ['image'],
            maxDuration: 30,
            camera: 'back',
            success: function (res) {
                var tempFilePath = res.tempFiles[0].tempFilePath;
                wx.uploadFile({
                    url: 'http://' + ipconfig + ':8080/tool/upload',
                    filePath: tempFilePath,
                    name: 'file',
                    header: {
                        'Authorization': wx.getStorageSync('token')
                    },
                    success: function (res) {
                        const data1 = JSON.parse(res.data)
                        let array = that.data.moment.picture;
                        array.push('http://ruuqwf8y6.hn-bkt.clouddn.com/'+data1.data)
                        that.setData({
                            'moment.picture':array
                        })

                        console.log(that.data.moment.picture);
                    },
                    fail: function (err) {
                        console.log(err);
                    }
                });

            },
            fail: function (err) {
                console.log(err);
            }
        })
    },

    /**监听编辑器初始化完成时触发 */
    onBindReadyEditor(e){
        console.log('onBindReadyEditor---------------->', e.detail)
        
        // 或者，获取组件实例，调用组件的事件
        //let editor = this.selectComponent("#editor")
        //editor.setContents('666666')
    },

    /**编辑器内容改变时触发 */
    onBindInputEditor(e){
		console.log("onBindInputEditor--------------------------->", e.detail)               
    },
    /**编辑器失去焦点 */
	onBindBlur(e){
		this.setData({
			'moment.content':e.detail.html
		})
		
	},
    /**表单组件 */
    pickerConfirm(e) {
        this.setData({
          pickerHidden: true
        })
        this.setData({
          chosen: e.detail.value
        })
      },
    
      pickerCancel() {
        this.setData({
          pickerHidden: true
        })
      },
    
      pickerShow() {
        this.setData({
          pickerHidden: false
        })
      },
    
      formSubmit(e) {
        
        console.log(this.data.moment);

		this.setData({
			'moment.title':e.detail.value.title
		})
		wx.request({
            url: 'http://' + ipconfig + ':8080/moments/insertQuest',
            data: this.data.moment,
            method: 'POST',
            header: {
                'Authorization': wx.getStorageSync("token")
            },
            success(res) {
                wx.navigateBack();
            },
            fail: function (err) {
                console.log(err);
            }
        })

      },
    
      formReset(e) {
        console.log('form发生了reset事件，携带数据为：', e.detail.value)
        wx.navigateBack()
      }
      
    

})